package q2d.common.models;

import java.io.Serializable;

import q2d.common.models.units.Bullet;
import q2d.common.models.units.Player;


public class GameContainer implements Serializable {
        
        private double bulletsArray[];
        private int bulletsHpsArray[];
        private float playersArray[];
        private String playersNamesArray[];
        private int playersTeamsArray[];
        public int playerDeathCounter;
        public int playerHP;

        transient private int currentPlayersCount;
        transient private int currentPlayersNamesCount;
        transient private int currentPlayersTeamsCount;

        transient private int currentBulletsCount;
        transient private int currentBulletsHpsCount;

        // informacje o flagach
        public int redFlagX;
        public int redFlagY;
        public int blueFlagX;
        public int blueFlagY;

        // informacje o punktach dla druzyn
        public int redTeamScore;
        public int blueTeamScore;

        public GameContainer(final int bullets_count, final int players_count){
                // pociski
                bulletsArray = new double[bullets_count*4];
                bulletsHpsArray = new int[bullets_count];

                // punkty
                redTeamScore = 0;
                blueTeamScore = 0;

                // gracze
                playersArray = new float[players_count*3];
                playersNamesArray = new String[players_count];
                playersTeamsArray = new int[players_count];

                // liczniki
                playerDeathCounter = 0;
                playerHP = 100;

                // liczniki pozycji w tablicach
                currentPlayersCount = 0;
                currentPlayersNamesCount = 0;
                currentPlayersTeamsCount = 0;

                currentBulletsCount = 0;
                currentBulletsHpsCount = 0;
        }


        
        public void addPlayer(Player p){
                playersArray[currentPlayersCount++] = p.x;
                playersArray[currentPlayersCount++] = p.y;
                playersArray[currentPlayersCount++] = p.rotation;
                playersNamesArray[currentPlayersNamesCount++] = p.nick; 
                playersTeamsArray[currentPlayersTeamsCount++] = p.team;
        }



        public void addBullet(Bullet b){
                bulletsArray[currentBulletsCount++] = b.x;
                bulletsArray[currentBulletsCount++] = b.y;
                bulletsArray[currentBulletsCount++] = b.vx;
                bulletsArray[currentBulletsCount++] = b.vy;
                bulletsHpsArray[currentBulletsHpsCount++] = b.power;
        }


        public Player getPlayer(int i){
                Player p = new Player(playersTeamsArray[i]);
                p.x = (int)playersArray[i*3];
                p.y = (int)playersArray[i*3+1];
                p.rotation = (float)playersArray[i*3+2];
                p.nick = playersNamesArray[i];
                return p;
        }


        public Bullet getBullet(int i){
                Bullet b = new Bullet();
                b.x = bulletsArray[i*4];
                b.y = bulletsArray[i*4+1];
                b.vx = bulletsArray[i*4+2];
                b.vy = bulletsArray[i*4+3];
                b.type = Bullet.TYPE_1;
                b.power = bulletsHpsArray[i];
                return b;
        }


        public int getPlayersCount(){
                return playersArray.length/3;
        }


        public int getBulletsCount(){
                return bulletsArray.length/4;
        }
}